package com.whpost.service.dao.stamp;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whpost.service.entity.stamp.StampCardOrder;
import org.apache.ibatis.annotations.*;

import java.util.Date;

public interface StampCardOrderMapper extends BaseMapper<StampCardOrder> {

    //查询订单
    @Select("select * from stamp_card_order where id=#{0}")
    @Results(id="cardOrderMap",value = {
            @Result(column="t_hyxx_id",property="tHyxx",
                    one=@One(
                            select="com.whpost.service.dao.t.THyxxDao.getHyxxContainNickname")
            ),
            @Result(column="t_hyxx_id",property="tHyxxId"),
            @Result(column="hd_id",property="stampHd",
                    one=@One(
                            select="com.whpost.service.dao.stamp.StampHdMapper.getById")
            ),
            @Result(column="hd_id",property="hdId"),
            @Result(column="id",property="tWxOrder",
                    one=@One(
                            select="com.whpost.service.dao.wx.TWxOrderDao.getTWxOrderByZblsh")
            ),
            @Result(column="id",property="id")
    })
    StampCardOrder getById(Long id);

    //根据条件获取分页信息
    @Select("select * from stamp_card_order where ${ew.sqlSegment} ")
    @ResultMap(value="cardOrderMap")
    IPage<StampCardOrder> getStampCardOrderLPage(Page<StampCardOrder> page, @Param("ew") QueryWrapper wrapper);

    @Update("update stamp_card_order set scbz='1' where id=#{id}")
    int updateScbz1(String id);

    @Select("select wx_id from stamp_xm where id in (select xm_id from stamp_hd where id in (select hd_id from stamp_card_order where id=#{id}))")
    String getWxIdByOrderId(String id);

    //更新设置为退款成功
    @Update("update stamp_card_order set istk='1',tkrq=#{tkrq},tk_czy_id=#{czyId} where id= #{lsh}")
    int updateTkbz(@Param(value = "lsh") Long lsh,@Param(value = "czyId") Long czyId,@Param(value = "tkrq") Date tkrq);


}